/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.brandongogetap.stickyheaders.viewholder;

import com.brandongogetap.stickyheaders.ResourceTable;
import com.brandongogetap.stickyheaders.model.ItemModel;
import com.brandongogetap.stickyheaders.ultimateprovider.EventTransmissionListener;
import com.brandongogetap.stickyheaders.ultimateprovider.UltimateProvider;
import com.brandongogetap.stickyheaders.ultimateprovider.ViewHolder;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.Text;
import ohos.agp.components.element.ShapeElement;

public class ItemViewHolder extends ViewHolder<ItemModel> {
    private DirectionalLayout itemLayout;
    private Text tvTitle;
    private Text tvMessage;

    public ItemViewHolder(EventTransmissionListener eventTransmissionListener, Component component, UltimateProvider provider, ComponentContainer componentContainer) {
        super(eventTransmissionListener, component, provider, componentContainer);
        itemLayout = (DirectionalLayout) findComponentById(ResourceTable.Id_itemLayout);
        tvTitle = (Text) findComponentById(ResourceTable.Id_tv_title);
        tvMessage = (Text) findComponentById(ResourceTable.Id_tv_message);
    }

    @Override
    public void onDataBound() {
        tvTitle.setText(getModel().getTitle());
        tvMessage.setText(getModel().getMessage());
        ShapeElement element = new ShapeElement();
        RgbColor rgbColor = new RgbColor(0);
        element.setRgbColor(rgbColor);
        itemLayout.setBackground(element);
    }
}
